package javaweb.sevice.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import javaweb.mapper.LogMapper;
import javaweb.pojo.LogPageResult;
import javaweb.pojo.LogQueryParam;
import javaweb.pojo.OperateLog;
import javaweb.sevice.LogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class LogServiceImpl implements LogService {

    @Autowired
    private LogMapper logMapper;

    /*
    * 分页查询查询所有日志
    * */
    @Override
    public LogPageResult getLog(LogQueryParam logQueryParam) {
        //调用PageHelper对象
        PageHelper.startPage(logQueryParam.getPage(), logQueryParam.getPageSize());

        //调用Mapper接口
        List<OperateLog> logList = logMapper.selectLog(logQueryParam);
        Page<OperateLog> p = (Page<OperateLog>) logList;

        //封装对象返回
        return new LogPageResult(p.getTotal(), p.getResult());
    }
}
